﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;

namespace ecomerci
{
    public partial class selectCustomer : Form
    {
        sqlite sql;
        applicationLogic logic;
        public string select_customer_id { get; set; }
        public string select_first_name { get; set; }
        public string select_last_name { get; set; }
        public string select_ebay_name { get; set; }
        public string select_street { get; set; }
        public string select_house_number { get; set; }
        public string select_area_code { get; set; }
        public string select_city { get; set; }
        public string select_email { get; set; }

        public selectCustomer()
        {
            logic = new applicationLogic();
            sql = new sqlite();
            
            InitializeComponent();
            dataGridView1.DataSource = logic.getCustomerDatabase();
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            try
            {
                getCustomer(dataGridView1.SelectedRows[0].Cells[2].Value.ToString());
            }
            catch (Exception ex)
            {
                logic.showException(ex);
            }
        }

        private void getCustomer(string Ebay_username)
        {
            try
            {
                customer customer = logic.getCustomer(Ebay_username);

                //select_customer_id = customer.Rows[0][0].ToString();
                select_first_name = customer.first_name.ToString();
                select_last_name = customer.last_name.ToString();
                string[] adress = customer.adress.ToString().Split(' ');
                select_street = adress[0];
                select_house_number = adress[1];
                select_area_code = customer.area_code.ToString();
                select_city = customer.city.ToString();
                select_ebay_name = customer.ebay_username.ToString();
                select_email = customer.email.ToString();
            }
            catch (Exception ex)
            {
                logic.showException(ex);
            }
        }
    }
}
